package dialogs;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;

import com.example.administrator.newxlmedical.R;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import custom.MyDialog;
import utils.MD5;
import utils.ToastUtil;

/**
 * Created by Administrator on 2018/6/1.
 */

public class UserManagePasswordDialog extends MyDialog {
    @BindView(R.id.et_dialog_user_manage_password)
    EditText etPassword;
    @BindView(R.id.et_dialog_user_manage_password_again)
    EditText etAgain;
    @BindView(R.id.bt_dialog_user_manage_password_cancel)
    Button btCancel;
    @BindView(R.id.bt_dialog_user_manage_password_modify)
    Button btModify;
    @BindView(R.id.iv_dialog_user_manage_password_close)
    ImageView ivClose;
    private Context mContext;
    private OnClickListener onClickListener;


    public UserManagePasswordDialog(@NonNull Context context, int themeResId, OnClickListener onClickListener) {
        super(context, themeResId);
        this.onClickListener = onClickListener;
        mContext = context;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_user_manage_password);
        ButterKnife.bind(this);
    }

    @OnClick({R.id.bt_dialog_user_manage_password_cancel, R.id.bt_dialog_user_manage_password_modify,R.id.iv_dialog_user_manage_password_close})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.bt_dialog_user_manage_password_cancel:
                dismiss();
                break;
            case R.id.iv_dialog_user_manage_password_close:
                dismiss();
                break;
            case R.id.bt_dialog_user_manage_password_modify:
                if (TextUtils.isEmpty(etPassword.getText().toString()) && TextUtils.isEmpty(etAgain.getText().toString())) {
                    ToastUtil.showToast(mContext, "请输入密码!");
                } else {
                    if (!etPassword.getText().toString().equals(etAgain.getText().toString())) {
                        ToastUtil.showToast(mContext, "两次密码不一致，请重新输入!");
                    } else {
                        onClickListener.onModify(MD5.md5(etPassword.getText().toString()), this);
                    }
                }
                break;
        }
    }

    public interface OnClickListener {
        void onModify(String password, UserManagePasswordDialog dialog);

    }
}
